import pandas as pd
import csv

df = pd.read_csv("D:\py\pythonProject\population-data\data\originalData\男性个年龄年度数据 .csv", skiprows=2)
df = df.iloc[:-2]
df['指标'] = df['指标'].str.replace('男性人口数(人口抽样调查)(人)', '', regex=False)
print(df.head())

first_row = df.iloc[0]
print(first_row)

df_normalized = df.copy()
df_normalized.iloc[1:, 1:] = df.iloc[1:, 1:].div(first_row[1:], axis=1).round(4)
df_normalized=df_normalized.drop(df_normalized.index[0])

df_normalized.iloc[:, 1:] = df_normalized.iloc[:, 1:].applymap(lambda x: round(x * 100, 2))
output_file_path = r'D:\py\pythonProject\population-data\data\temp\男生年度数据.csv'
df_normalized.to_csv(output_file_path, encoding="gbk")
